class Solution {
public:
    int reverse(int x) {
        int flag = 1;
        if (x < 0) {
            flag = -1;
            x *= -1;
        }
        int ret = 0;
        while (x) {
            ret = (ret * 10) + x%10;
            x /= 10;
        }
        return ret * flag;
    }
};
